package com.lions.client.view.gui;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.StackLayoutPanel;
import com.lions.client.controller.Controller;
import com.lions.client.model.Model;
import com.lions.client.view.basepanel.BasePanel;
import com.lions.client.view.mappanel.MapPanel;
import com.lions.client.view.mappanel.SandboxMapPanel;
import com.lions.client.view.modulepanel.ModulePanel;
import com.lions.client.view.weather.WeatherPanel;

/**
 * This is the GUI for the main panel. This panel holds all of the panels used
 * for functionality. This panel also takes/ gives the model and/or controller
 * to every panel.
 * 
 * @author Brad
 * 
 */
public class MainPanel extends ScrollPanel {

	/**
	 * Created after successful login.
	 */
	public MainPanel(Model m, Controller c) {
		super();
		model = m;
		control = c;
		initComponents();
		tenDay = new TenDayPopup();
		tenDay.center();
		if (tenDay.checkRecal() == true){
			tenDay.show();
		}
	}

	/**
	 * Builds the GUI components There is: menuBar (Top) buttonPanel (North)
	 * modulePanel (West) splitLayout (Center)
	 * 
	 */
	private void initComponents() {
		// Set CSS for this panel
		// this.setStyleName("scrollpanel");

		// Controller panel
		northPanel = new DockPanel();
		northPanel.add(control.getControllerPanel(), DockPanel.CENTER);
		northPanel.addStyleName("northpanel");

		// Stack Layout Panel for map and stats
		mapPanel = new MapPanel(model);
		mapPanel.addStyleName("mappanel");
		centerStackLayout = new StackLayoutPanel(Unit.EM);
		centerStackLayout.setStyleName("splitlayoutstyle");
		centerStackLayout.add(mapPanel, new HTML("Map"), tabSize);
		sandboxPanel = new SandboxMapPanel(model);
		sandboxPanel.addStyleName("mappanel");
		centerStackLayout.add(sandboxPanel, new HTML("Sandbox"), tabSize);
		centerPanel = new LayoutPanel();
		centerPanel.add(centerStackLayout);
		centerPanel.addStyleName("centerpanel");

		// Base side panel
		basePanel = new BasePanel(model, control, mapPanel);
		eastPanel = new LayoutPanel();
		eastPanel.add(basePanel);
		eastPanel.setStyleName("sidepanel");

		// Module side panel
		modulePanel = new ModulePanel(model, control, mapPanel, sandboxPanel,
				basePanel);
		westPanel = new LayoutPanel();
		westPanel.add(modulePanel);
		westPanel.addStyleName("sidepanel");
		sandboxPanel.addModulePanel(modulePanel);

		// Additional Content Panel
		southPanel = new DockPanel();
		southPanel.add(new WeatherPanel(), DockPanel.CENTER);
		southPanel.addStyleName("southpanel");

		// Add panels to widgetPanel
		widgetPanel = new DockPanel();
		widgetPanel.setSpacing(4);
		widgetPanel.add(northPanel, DockPanel.NORTH);
		widgetPanel.add(southPanel, DockPanel.SOUTH);
		widgetPanel.add(westPanel, DockPanel.WEST);
		widgetPanel.add(eastPanel, DockPanel.EAST);
		widgetPanel.add(centerPanel, DockPanel.CENTER);

		// Menu Bar
		menu = new MyMenuBar(model, modulePanel, mapPanel);
		menu.addStyleName("menubar");

		// Add the panels to this panel
		mainDock = new DockPanel();
		mainDock.addStyleName("dockpanel");
		mainDock.setHorizontalAlignment(DockPanel.ALIGN_CENTER);
		mainDock.add(menu, DockPanel.NORTH);
		mainDock.add(widgetPanel, DockPanel.CENTER);

		this.add(mainDock);
	}

	private int tabSize = 2;
	private MyMenuBar menu;
	private DockPanel mainDock;
	private DockPanel widgetPanel;
	private DockPanel northPanel;
	private DockPanel southPanel;
	private LayoutPanel westPanel;
	private LayoutPanel eastPanel;
	private LayoutPanel centerPanel;
	private StackLayoutPanel centerStackLayout;
	private ModulePanel modulePanel;
	private BasePanel basePanel;
	private MapPanel mapPanel;
	private SandboxMapPanel sandboxPanel;
	private Model model;
	private Controller control;
	private TenDayPopup tenDay;

}
